﻿using System;
using Optparse;
using Optparse.Options;
using NUnit.Framework;
using System.Net;

namespace Optparse.Tester {
    [TestFixture]
    public class OptionParserTester {
        [Test]
        public void TestOptionParse() {
            OptionParser parser = new OptionParser("usage:contl.exe [options]", "1.3.3");
            parser.AddOption(new StringArgOption("-f", "--file", "FILENAME", "Type a file name, use to read data to buffer."));
            parser.AddOption(new IPAddressArgOption("-i", "--ip", "IP", "Type ip address, if null 127.0.0.1 will be used.", "127.0.0.1"));
            parser.AddOption(new IntArgOption("-p", "--port", "PORT", "Type a port for socket listened, if null 21121 will be used.", 21121));

            OptionGroup group = new OptionGroup("Debug mode");
            group.AddOption(new BoolArgOption("-d", "--debug", string.Empty, "Indicate the debug mode is enabled. if true, enabled.", true));
            group.AddOption(new BoolArgOption("-P", "--print", string.Empty, "", false));
            parser.AddOptionGroup(group);

            parser.Parse("console.exe -f \"c:\\sss\\ttt.txt\" -i 192.168.1.1 -d");
            Assert.AreEqual("c:\\sss\\ttt.txt", parser.GetValue("-f"));
            Assert.AreEqual(IPAddress.Parse("192.168.1.1").Address, ((IPAddress)parser.GetValue("-i")).Address);
            Assert.IsTrue((bool)parser.GetValue("-d"));
        }
    }
}
